﻿namespace IBTrader.Indicator.Channel
{
    using IBTrader.Indicator;
    using IBTrader.Modules.Read;
    using IBTrader.Charts;

    /// <summary>
    /// Quantifies a security's price relative to the upper and lower Bollinger Band. 
    /// </summary>
    class BollingerBandB : Base
    {
        private Line line;
        private readonly BollingerBand bollingerBand;
        public BollingerBandB(Worker worker) : base(worker, new ChartArgs { Group = 1 })
        {
            Line up = null;
            bollingerBand = new BollingerBand(worker);
            bollingerBand.Up += (_, line) => up = line;
            bollingerBand.Down += (_, down) => OnHit(line, NaN((line.Price - down.Price) / (up.Price - down.Price)));
        }
        public override void Add(object sender, Line line)
        {
            this.line = line;
            bollingerBand.Add(sender, line);
        }
    }
}
